/*
 * @FilePath: common.ts
 * @@author: wjj
 * @Date: 2025-07-23 16:42:29
 * @@Description: new js file
 */
import { ElMessage } from 'element-plus'
import axios from 'axios'
export const sleep = (time: number) => {
  return new Promise((resolve) => setTimeout(resolve, time * 1000))
}
//复制
export const copyString = async (text: any) => {
  try {
    await navigator.clipboard.writeText(text)
    ElMessage.success('数据已复制到剪贴板！')
  } catch (err) {
    ElMessage.error('复制失败')
    console.error('复制失败:', err)
  }
}
// 写入文本到剪贴板
export const fallbackCopy = (text: any) => {
  const textarea = document.createElement('textarea')
  textarea.value = text
  textarea.style.position = 'fixed' // 避免页面滚动
  document.body.appendChild(textarea)
  textarea.select()

  try {
    const success = document.execCommand('copy')
    if (!success) throw new Error('复制失败')
    ElMessage.success('复制成功: ' + text)
    console.log('复制成功（旧方法）')
  } catch (err) {
    ElMessage.error('复制失败')
    console.error('复制失败:', err)
  } finally {
    document.body.removeChild(textarea)
  }
}

export const nimi_login = (user_phone: any, device_id: any) => {
  const postData = {
    auth_code: user_phone.slice(-1),
    device_id: device_id,
    phone_number: '+86 ' + user_phone,
  }
  const nimi_params = {
    loc: 'en',
    'device-id': device_id,
    version: '2.46.2',
    lang: 'zh',
    platform: 'android',
    model: 'RMX2117',
    os: '31',
  }
  const nimi_headers = {
    // 'User-Agent': 'okhttp/4.12.0',
    Accept: '*/*',
    'X-DFPID':
      '0TrbhnR62mWxr7rk8w8hNOCUSzQ8p7olYourTh1lULMEuKbeGCUUy+154TV2pT/bOXjumKe+cltqcfrIidg9yw==',
    'X-SIUA':
      'tzFeJ3nonepLnMHO1OnuQ77KTS+65KrCoN2ANNfg0lnMKTSOvyNVgKY7rdc4JWjR+BzoFYyNC6g1DuIJ8AJiggTIgm9itZf3fg/epJtfhcs=',
    'Content-Type': 'application/json; charset=UTF-8',
    // Host: 'test.nimiproject.com',
  }
  return axios.post(
    'http://test.nimiproject.com/api/ms/v1/nimi/login',
    postData,
    {
      params: nimi_params, // 查询参数
      headers: nimi_headers, // 请求头
    },
  )
  return
}
